/*
 * @Author: HaoyangDu@wits.com
 * @description:
 * @param:
 * @return:
 */
/**
 * @Author: HaoyangDu
 * @Email: HaoyangDu@wits.com
 * @Date: 2024-03-25 16:09:53
 * @LastEditTime: 2024-05-16 15:20:19
 * @LastEditors: Please set LastEditors
 * @Description:
 * @FilePath: \hfxed\src\utils\utils.js
 */

/**
 * @description: 按千位逗号分割
 * @param {*} s 需要格式化的数值
 * @param {*} type 判断格式化后是否需要小数位
 * @return {*} 返回格式化后的数值字符串
 */
export const formatNumber = (s, type = 0) => {
  if (/[^0-9\.]/.test(s)) return "0";
  if (s == null || s == "") return "0";
  s = s.toString().replace(/^(\d*)$/, "$1.");
  s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
  s = s.replace(".", ",");
  var re = /(\d)(\d{3},)/;
  while (re.test(s)) s = s.replace(re, "$1,$2");
  s = s.replace(/,(\d\d)$/, ".$1");
  if (type == 0) {
    // 不带小数位(默认是有小数位)
    var a = s.split(".");
    if (a[1] == "00") {
      s = a[0];
    }
  }
  return s;
};

import config from "./config.js";
import { sm2 } from "sm-crypto";
/**
 * @description: sm2加密
 * @param {*} str
 * @return {*}  加密后的params
 */
export const doEncryptSM2 = (str) => {
  // let encryptData = sm2.doEncrypt(str, config.SM2PublicKey)
  // return encryptData
  return str;
};
/**
 * @description: sm2解密
 * @param {*} str
 * @return {*}  解密后的data
 */
export const doDecryptSM2 = (str) => {
  // let decryptData = sm2.doDecrypt(str, config.SM2PrivateKey)
  // return decryptData
  return str;
};

/**
 * @description: 获取年月日 YY-MM-DD
 * @param {*} str
 * @return {*}
 */
export const getFormatDate = (str) => {
  //获取年份
  let year = new Date(str).getFullYear();
  //获取月份，获取的月份比实际小1，所以在使用的时候需要+1
  let month = new Date(str).getMonth() + 1;
  //获取日
  let date = new Date(str).getDate();
  //获取时
  let time = year + "-" + month + "-" + date;
  console.log(time);
  //输出样式：2020-10-25
  return time;
};

/**
 * @description: 校验手机号
 * @param {type}
 * @return:
 * @Date Changed:
 */
export const checkMobile = (param) => {
  let reg = /^1\d{10}$/;
  return reg.test(param);
};